Fix VB compiler crashes when decoding attributes#61537
Fix VB compiler crashes when decoding attributes#61537AlekseyTs merged 7 commits intodotnet:mainfrom
Conversation
| Case Else | ||
| diagnostics.Add(ERRID.ERR_BadAttribute1, If(nodeOpt IsNot Nothing, nodeOpt.ArgumentList.Arguments(0).GetLocation(), NoLocation.Singleton), Me.AttributeClass) | ||
| diagnostics.Add(ERRID.ERR_BadAttribute1, | ||
| If(nodeOpt IsNot Nothing, If(nodeOpt.ArgumentList IsNot Nothing AndAlso nodeOpt.ArgumentList.Arguments.Count > 0, nodeOpt.ArgumentList.Arguments(0).GetLocation(), nodeOpt.GetLocation()), NoLocation.Singleton), |
There was a problem hiding this comment.
Can these still use the helper, even if they only care about the location?
There was a problem hiding this comment.
@333fred Do I need to share the helper among classes too? e.g, make it publicly available from AttributeData
| Dim argSyntaxLocation As Location = If(arguments.AttributeSyntaxOpt IsNot Nothing, | ||
| arguments.AttributeSyntaxOpt.ArgumentList.Arguments(1).GetLocation(), | ||
| NoLocation.Singleton) |
There was a problem hiding this comment.
I wasn't able to write a test that makes a crash here, so I didn't make a change.
In case someone was able to, let me know.
|
Do we have similar issues with C# compiler? At least we probably should add similar tests. |
| @@ -3763,15 +3821,86 @@ end class | |||
|
|
|||
| Dim comp = CompilationUtils.CreateCompilationWithMscorlib40AndVBRuntime(source) | |||
| comp.VerifyDiagnostics(Diagnostic(ERRID.ERR_OmittedArgument2, "FileIOPermission").WithArguments("action", "Public Overloads Sub New(action As System.Security.Permissions.SecurityAction)"), | |||
There was a problem hiding this comment.
I used it for new tests, but makes sense to use in this modified existing test too. Will do.
| @@ -3812,12 +3941,12 @@ end class | |||
|
|
|||
| Dim comp = CompilationUtils.CreateCompilationWithMscorlib40AndVBRuntimeAndReferences(source) | |||
| comp.VerifyDiagnostics( | |||
I think C# doesn't have the bug, but I'll double check and add tests. |
|
|
||
| Dim comp = CompilationUtils.CreateCompilationWithMscorlib40AndVBRuntime(source) | ||
| comp.AssertTheseDiagnostics(<errors><![CDATA[ | ||
| BC40000: 'RequestMinimum' is obsolete: 'Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.'. |
| If(nodeOpt IsNot Nothing, nodeOpt.ArgumentList.Arguments(0).GetLocation(), NoLocation.Singleton), | ||
| If(nodeOpt IsNot Nothing, nodeOpt.ArgumentList.Arguments(0).ToString(), "")) | ||
| ' BC31215: SecurityAction value '{0}' is invalid for PrincipalPermission attribute | ||
| Dim valueLocation = GetArgumentAndLocation(nodeOpt, securityAction) |
| Return GetArgumentAndLocation(nodeOpt, 0).Location | ||
| End Function | ||
|
|
||
| Private Shared Function GetArgumentAndLocation(nodeOpt As AttributeSyntax, value As Integer) As (Argument As String, Location As Location) |
| Return GetArgumentAndLocation(nodeOpt, 0).Location | ||
| End Function | ||
|
|
||
| Private Shared Function GetArgumentAndLocation(nodeOpt As AttributeSyntax, value As Integer) As (Argument As String, Location As Location) |
| Return Nothing | ||
| End Function | ||
|
|
||
| Private Shared Function GetLocationForAttributeDiagnostic(nodeOpt As AttributeSyntax) As Location |
| If(nodeOpt IsNot Nothing, nodeOpt.ArgumentList.Arguments(0).GetLocation(), NoLocation.Singleton), | ||
| If(nodeOpt IsNot Nothing, nodeOpt.ArgumentList.Arguments(0).ToString(), "")) | ||
| ' BC31215: SecurityAction value '{0}' is invalid for PrincipalPermission attribute | ||
| Dim valueLocation = GetArgumentAndLocation(nodeOpt, securityAction) |
| Else | ||
| location = NoLocation.Singleton | ||
| End If | ||
| diagnostics.Add(ERRID.ERR_BadAttribute1, If(nodeOpt IsNot Nothing, location, NoLocation.Singleton), attrData.AttributeClass) |
|
Done with review pass (commit 3) |
|
It looks like there are already C# tests: roslyn/src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests_Security.cs Lines 1656 to 1707 in d46613c |
Do they cover all the attributes that we added tests for in this PR for VB? If not, let's open an issue to follow up with tests for C#, listing specific new VB unit-tests. I( do not want to hold this PR because of that. |
|
@333fred, @dotnet/roslyn-compiler For the second review on a community PR. |
They all share the same code path, but I agree the tests are good to have. I opened #61794. |
|
@dotnet/roslyn-compiler For the second review on a community PR. |
1 similar comment
|
@dotnet/roslyn-compiler For the second review on a community PR. |
| End If | ||
| Else | ||
| location = NoLocation.Singleton | ||
| End If |
There was a problem hiding this comment.
Is this the same code used in other Source*Symbol methods? If so, consider extracting a helper method.
| <![CDATA[ | ||
| Imports System.Runtime.InteropServices | ||
|
|
||
| <Assembly: TypeLibVersionAttribute(1, -1)> ' Not valid. major is negative. |
|
@Youssef1313 Thanks for the contribution |
Fixes #61492